<?php
/**
 * Created by PhpStorm.
 * User: work
 * Date: 18-8-11
 * Time: 下午5:01
 */

namespace PddWechat\Models\Pddorder\Service;


use Dai\Framework\Base\BaseSessionInfo;
use PddWechat\Models\Pddorder\Data\PddOrderData;
use PddWechat\Models\Pddorder\DataObject\PddOrderDo;

class BuyList
{
    /**
     * @param $basePageInfo
     * @return array
     */
    public function execute($basePageInfo) {
        /** @var BaseSessionInfo $sessionData */
        $sessionData = $basePageInfo->sessionInfo;

        $params = $basePageInfo->params;
        $pddOrderData = new PddOrderData();

        $pddOrderDo = new PddOrderDo();
        $pddOrderDo->uid = $sessionData->uid;

        $orderBy = " id desc LIMIT ".$params->pn."," .$params->rn;
        $output = [
            'total' => $pddOrderData->totalObj($pddOrderDo),
            'nextUrl' => '/admin/order/list?pn=' .($params->pn + $params->rn),
            'preUrl' => '/admin/order/list?pn=' .($params->pn - $params->rn > 0 ? $params->pn - $params->rn : 0 ),
            'list' => $pddOrderData->selectList($pddOrderDo, $orderBy),
        ];
        return $output;
    }
}